package Entities;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;

import Db.*;
import Enum.*;

public  class MainTable  {
	
	static Table table1;
	
public MainTable(Composite arg0) {
		table1 = new Table(arg0, SWT.BORDER | SWT.FULL_SELECTION);
		table1.setBounds(10, 82, 599, 304);
		table1.setHeaderVisible(true);
		table1.setLinesVisible(true);		
}

public Table getTable(){
	return table1;
}


public static void fillTable(Table table_1) throws SQLException{
	Connection conn = Db.DbEntities.Conn();
		
	 try {
		ResultSet sqlResults = Db.DbEntities.sqlQuery(conn);
		
	
		while (sqlResults.next()) {
    		  String word_source = sqlResults.getString(	Vocabulary.word_source.getEnumValue());
    		  String word_target = sqlResults.getString(Vocabulary.word_target.getEnumValue());
    		  
    		  TableItem tableRow = new TableItem(table_1, SWT.NULL);
    		  tableRow.setText(0,word_source);
    		  tableRow.setText(1,word_target);
    		}

    

	 } catch (SQLException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	 conn.close();
}
	

}
